from typing import List, Dict, Optional, Any
from pydantic import BaseModel, Field
from app.schemas.facenet_base_schema import AlgorithmRequest, AlgorithmResponse, AlgorithmMiddleResponse, TaskStatus
from app.schemas.assets_schema import Node, Edge, KnowledgeGraph


class GraphInput(BaseModel):
    """图输入参数"""
    graph: KnowledgeGraph
    threshold: float = Field(default=0.7, description="异常检测阈值，范围0-1之间")
    has_labels: bool = Field(default=False, description="图中的边是否已有标签")


class AEDSRequest(AlgorithmRequest):
    """异常边检测请求"""
    input_params: GraphInput


class AnomalousEdge(BaseModel):
    """异常边"""
    from_node: str
    to_node: str
    anomaly_score: float


class GraphOutput(BaseModel):
    """图输出参数"""
    anomalous_edges: List[AnomalousEdge]
    total_edges: int
    anomalous_count: int


class AEDSResponse(BaseModel):
    """异常边检测响应"""
    task_id: str
    task_callback_url: Optional[str] = None
    task_status: TaskStatus
    task_progress: int = 0
    task_logs: Optional[str] = None
    output_params: GraphOutput
    error_message: Optional[str] = None


class AEDSMetric(BaseModel):
    """性能指标"""
    precision: Optional[float] = None
    recall: Optional[float] = None
    f1_score: Optional[float] = None
    auc: Optional[float] = None


class AEDSMiddleResponse(BaseModel):
    """异常边检测中间响应"""
    task_id: str
    task_callback_url: str
    task_status: TaskStatus
    task_progress: int = 0
    task_logs: Optional[str] = None
    input_params: GraphInput
    error_message: Optional[str] = None
    metrics: Optional[List[AEDSMetric]] = [] 